import { Injectable, Autowired } from '@opensumi/di';
import { IMessageService } from '@opensumi/ide-overlay';
import { URI, getIcon } from '@opensumi/ide-core-browser';
import { ILowcodeConnectionServerPath, ILowcodeNodeService, ILowcodeService, LowcodePageScheme } from '../common';
import { RPCService } from '@opensumi/ide-connection';
import { WorkbenchEditorService } from '@opensumi/ide-editor';

@Injectable()
export class LowcodeService extends RPCService implements ILowcodeService {
  @Autowired(IMessageService)
  private messageService: IMessageService;

  @Autowired(ILowcodeConnectionServerPath)
  private lowcodeNodeService: ILowcodeNodeService;

  @Autowired(WorkbenchEditorService)
  private readonly editorService: WorkbenchEditorService;

  onMessage = (message: string) => {
    this.messageService.info(message);
  };

  showMessage = (message: string) => {
    console.log('LowcodeService showMessage', message)
    this.lowcodeNodeService.showMessage(message);
  };

  openPage = async (title: string) => {
    const uri = `${LowcodePageScheme}://?name=${title}`;
    this.editorService.open(new URI(uri));
  };
}
